<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- 新 Bootstrap4 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">

    <link rel="stylesheet" href="../../../../common/css/bootstrap-table.min.css">
    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>

    <script src="../../../../common/js/bootstrap-table.min.js"></script>
    <script src="../../../../common/js/bootstrap-table-zh-CN.min.js"></script>

    <!-- bootstrap.bundle.min.js 用于弹窗、提示、下拉菜单，包含了 popper.min.js -->
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>

    <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>

    <link href="../../../../static/css/jquery.dataTables.min.css" rel="stylesheet">
    <link href="../../../../static/css/style.css" rel="stylesheet">
</head>
<body>

<table id="tbodyShow">

</table>


<!-- 模态框 -->
<div class="modal fade" id="myModal">
    <div class="modal-dialog modal-xl">
        <div class="modal-content">

            <!-- 模态框头部 -->
            <div class="modal-header">
                <h4 class="modal-title">入库制定单</h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>

            <!-- 模态框主体 -->
            <div class="modal-body">

                <div class="shadow" style="width: 80%;height: 30%;margin-top: 5px;margin-left: 10%;padding: 10px">
                    <div class="text-center">
                        <h2>入库调度单</h2>
                    </div>

                    <div class="form-group row">

                        <label for="gatherId" class="col-sm-2 col-form-label">申请单编号:</label>
                        <div class="col-sm-6">
                            <input class="form-control" readonly type="text" id="gatherId">
                        </div>
                    </div>
                    <div class="form-group row">

                        <label for="reason" class="col-sm-2 col-form-label">入库理由:</label>
                        <div class="col-sm-3">
                            <input class="form-control" readonly type="text" id="reason">
                        </div>
                        <div class="col-2"></div>
                        <label for="storer" class="col-sm-2 col-form-label">入库详细理由:</label>
                        <div class="col-sm-3">
                            <input class="form-control" readonly type="text" id="storer">
                        </div>
                    </div>

                    <div>

                        <table class="table">
                            <tbody>
                            <tr style="background-color: gray">
                                <th>产品名称</th>
                                <th>产品编号</th>
                                <th>应入库数量</th>
                                <th>已入库数量</th>
                                <th>操作</th>
                            </tr>
                            </tbody>
                            <tbody id="tbodyShow2">

                            </tbody>
                        </table>

                    </div>

                    <div class="form-group row">

                        <label for="amountSum" class="col-sm-2 col-form-label"> 应入库总件数：</label>
                        <div class="col-sm-3">
                            <input class="form-control" readonly type="text" id="amountSum">
                        </div>
                        <div class="col-2"></div>
                        <label for="dd" class="col-sm-2 col-form-label"> 已入库总件数：</label>
                        <div class="col-sm-3">
                            <input class="form-control" readonly type="text" value="0.0" id="dd">
                        </div>

                    </div>

                    <div class="form-group row">
                        <label for="costPriceSum" class="col-sm-2 col-form-label">应入库总金额；</label>
                        <div class="col-sm-3">
                            <input class="form-control" readonly type="text" id="costPriceSum">
                        </div>
                        <div class="col-2"></div>
                        <label for="aa" class="col-sm-2 col-form-label">已入库库总金额；</label>
                        <div class="col-sm-3">
                            <input class="form-control" readonly type="text" value="0.0" id="aa">
                        </div>
                    </div>




                </div>

            </div>

            <!-- 模态框底部 -->
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            </div>

        </div>
    </div>
</div>




<!-- 模态框 -->
<div class="modal fade" id="myModal2">
    <div class="modal-dialog modal-xl">
        <div class="modal-content">

            <!-- 模态框头部 -->
            <div class="modal-header">
                <h4 class="modal-title">入库制定单</h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>

            <!-- 模态框主体 -->
            <div class="modal-body">
                <div style="margin-left: 10%">
                    <input id="SGDid" type="text" style="display: none">
                    <button class='btn btn-primary'  onclick="updateS_GATHER_DETAILS()"data-dismiss="modal">提交</button>
<!--                    <button class='btn btn-primary' data-dismiss="modal">返回</button>-->
                </div>
                <div class="shadow" style="width: 80%;height: 30%;margin-top: 5px;margin-left: 10%;padding: 10px">
                <div class="form-group row">
                    <label for="gatherId2" class="col-sm-2 col-form-label">申请单编号:</label>
                    <div class="col-sm-3">
                        <input class="form-control" readonly type="text" id="gatherId2">
                    </div>
                    <div class="col-2"></div>
                    <label for="productId2" class="col-sm-2 col-form-label">产品编号:</label>
                    <div class="col-sm-3">
                        <input class="form-control" readonly type="text" id="productId2">
                    </div>
                </div>

                <div class="form-group row">
                    <label for="productName2" class="col-sm-2 col-form-label">产品名称:</label>
                    <div class="col-sm-3">
                        <input class="form-control" readonly type="text" id="productName2">
                    </div>
                    <div class="col-2"></div>
                    <label for="costPrice2" class="col-sm-2 col-form-label">成品单价:</label>
                    <div class="col-sm-3">
                        <input class="form-control" readonly type="text" id="costPrice2">
                    </div>
                </div>

                <table class="table">
                    <tbody>
                    <tr style="background-color: gray">
                        <th>库房名称</th>
                        <th>存储地址编号</th>
                        <th>存储地址名称</th>
                        <th>存储单元简称</th>
                        <th>当前可存放数量</th>
                        <th>本次入库数量</th>
                    </tr>
                    </tbody>
                    <tbody id="tbody3">

                    </tbody>
                </table>

                <div class="form-group row">
                    <label for="register2" class="col-sm-2 col-form-label" > 登记人：</label>
                    <div class="col-sm-3">
                        <input class="form-control" readonly type="text" id="register2">
                    </div>
                    <div class="col-2"></div>
                    <label for="registerTime2" readonly class="col-sm-2 col-form-label">登记时间；</label>
                    <div class="col-sm-3">
                        <input class="form-control" readonly type="text" id="registerTime2">
                    </div>
                </div>

                <div class="form-group row">
                    <label for="amountSum" class="col-sm-2 col-form-label" > 应入库数：</label>
                    <div class="col-sm-3">
                        <input class="form-control" readonly type="text" id="amount2">
                    </div>
                    <div class="col-2"></div>
                    <label for="va" readonly class="col-sm-2 col-form-label">已入库数；</label>
                    <div class="col-sm-3">
                        <input class="form-control" readonly type="text" value="0.0" id="va">
                    </div>
                </div>

                <div class="form-group row">
                    <label for="subtotal2" class="col-sm-2 col-form-label" > 应入库成本：</label>
                    <div class="col-sm-3">
                        <input class="form-control" readonly type="text" id="subtotal2">
                    </div>
                    <div class="col-2"></div>
                    <label for="av" readonly class="col-sm-2 col-form-label">已入库成本；</label>
                    <div class="col-sm-3">
                        <input class="form-control" readonly type="text" value="0.0" id="av">
                    </div>
                </div>

                </div>
            </div>

            <!-- 模态框底部 -->
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            </div>

        </div>
    </div>
</div>

<script>
    $(function () {
        querySGatherPage()
    })
    function querySGatherPage() {
        $("#tbodyShow").bootstrapTable({
            method:"get",
            contentType:"application/json;charset=utf-8",
            url:"/querySGatherPage_develop.action",
            pageNumber:"1",
            pageSize:"5",
            height: 600,
            striped:true,
            pagination:true,
            sidePagination: "server",
            pageList: [3,5,7,9],
            queryParams:function(parts){
                return{
                    currentPage:(parts.offset/parts.limit)+1,
                    pageSize:parts.limit
                }
            },
            columns:[
                {title:"申请单编号",field:"gatherId",formatter:function(value,row,index){
                        let but="<button onclick='audit("+row.id+")' class='btn btn-link' data-toggle='modal' data-target='#myModal'>"+value+"</button>"
                        return but;
                    }},
                {title:"入库理由",field:"reason",formatter:function (value,row,index) {
                        let but=value=="R001-1"?"生产入库":value=="R001-2"?"库存初始":value=="R001-3"
                            ?"赠送":value=="R001-4"?"内部归还":"其他归还"
                        return but;
                    }},
                {title:"登记时间",field:"registerTime"},
                {title:"总件数",field:"amountSum"},
                {title:"总金额",field:"costPriceSum"},
                {title:"操作",field:"id",formatter:function (value,row,index) {
                        let but="<button class='btn btn-primary' onclick='scheduling("+value+")' data-toggle='modal' data-target='#myModal'>入库调度</button>";
                        return but;
                    }},
            ]
        })
    }
    let x;
    function scheduling(data) {
        x=data;
        $.ajax({
            type:"POST",
            url:"/queryBYIDXiaotan.action?id="+data,
            success:function (SGBean) {

                add(SGBean)

            }
        })
    }


    function add(sG) {

        $("#tbodyShow2").html("")
        $("#gatherId").val(sG.gatherId)
        $("#storer").val(sG.reasonexact)

        $("#reason").val(sG.reason=="R001-1"?"生产入库":sG.reason=="R001-2"?"库存初始":sG.reason=="R001-3"
            ?"赠送":sG.reason=="R001-4"?"内部归还":"其他归还")
        $("#amountSum").val(sG.amountSum)
        $("#costPriceSum").val(sG.costPriceSum)

        $("#register").val(sG.register)
        $("#registerTime").val(sG.registerTime)

        $("#checkTime").val(new Date().toLocaleString())
        let h=0;
        for (let i=0;i<sG.list.length;i++){
            if(sG.list[i].gatherTag=="K002-2"){
                $("#tbodyShow2").append("<tr>" +
                    "<td>" + sG.list[i].productName + "</td>" +
                    "<td>" + sG.list[i].productId + "</td>" +
                    "<td>" + sG.list[i].amount + "</td>" +
                    "<td>0.0</td>" +
                    "<td><button class='btn btn-primary')'>已调度</button></td>" +
                    "</tr>")
            }else {
                h+=1;
                $("#tbodyShow2").append("<tr>" +
                    "<td>" + sG.list[i].productName + "</td>" +
                    "<td>" + sG.list[i].productId + "</td>" +
                    "<td>" + sG.list[i].amount + "</td>" +
                    "<td>0.0</td>" +
                    "<td><button class='btn btn-primary' onclick='dd(" + JSON.stringify(sG) + "," + i + ")' data-toggle='modal' data-target='#myModal2'>调度</button></td>" +
                    "</tr>")
            }
        }
        if(h==0){
            alert("已全部调度！")
            window.location.reload()
        }
    }
    function dd(data,d) {

        $("#SGDid").val(data.list[d].id)
        $("#gatherId2").val(data.gatherId)
        $("#productId2").val(data.list[d].productId)
        $("#productName2").val(data.list[d].productName)
        $("#costPrice2").val(data.list[d].costPrice)
        $("#register2").val(data.register)
        $("#registerTime2").val(data.registerTime)
        $("#amount2").val(data.list[d].amount)
        $("#subtotal2").val(data.list[d].subtotal)

        $.ajax({
            type:"POST",
            url:"/queryByProductIdKey.action?pid="+data.list[d].productId,
            success:function (data2) {
                $("#tbody3").html("")
                // $("#tbody3").append("<tr>" +
                //     "<td>成品库</td>" +
                //     "<td>"+(data2.firstKindId)+"-"+(data2.secondKindId)+"-"+(data2.thirdKindId)+"</td>" +
                //     "<td>"+data2.firstKindName+"-"+data2.secondKindName+"-"+data2.thirdKindName+"</td>" +
                //     "<td>"+data.list[d].amountUnit+"</td>" +
                //     "<td>"+parseInt(data2.maxCapacityAmount)-parseInt(data2.amount)+"</td>" +
                //     "<td><input type='number' value='1'></td>" +
                //     "</tr>")
                $("#tbody3").append("<tr>" +
                    "<td>成品库</td>" +
                    "<td>"+data2.firstKindId+"-"+data2.secondKindId+"-"+data2.thirdKindId+"</td>" +
                    "<td>"+data2.firstKindName+"-"+data2.secondKindName+"-"+data2.thirdKindName+"</td>" +
                    "<td>"+data.list[d].amountUnit+"</td>" +
                    "<td id='kcc'>"+(parseInt(data2.maxCapacityAmount)-parseInt(data2.amount))+"</td>" +
                    "<td><input type='number' id='number1' readonly value='"+data.list[d].amount+"'></td>" +
                    "</tr>");
            }
        })

    }

    function f() {
        scheduling(x)
    }

    function updateS_GATHER_DETAILS() {
            $.ajax({
                type:"POST",
                url:"/updateS_GATHER_DETAILS.action?id="+$("#SGDid").val(),
                success:function () {
                    alert("调度成功")
                    f()
                }
            })
    }

</script>
</body>
</html>